﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

using mvcForum.Web.Interfaces;

namespace mvcForum.Web.Areas.ForumAdmin {

	public class ForumAdminAreaRegistration : AreaRegistration {

		public override string AreaName {
			get {
				return "ForumAdmin";
			}
		}

		public override void RegisterArea(AreaRegistrationContext context) {
			// Get an array containing the namespaces to use for controllers in the ForumAdmin area.
			// including the add-on and search configuration controllers.
			IEnumerable<String> namespaces =
				new String[] { "mvcForum.Web.Areas.ForumAdmin.Controllers" }.Concat<String>(
				DependencyResolver.Current.GetServices<IAntiSpamConfigurationController>().Select(c => c.GetType().Namespace).Distinct().Concat(
					DependencyResolver.Current.GetServices<ISearchConfigurationController>().Select(c => c.GetType().Namespace).Distinct()
				));

			context.MapRoute(
				"ForumAdmin_default",
				"forumadmin/{controller}/{action}/{id}",
				new { controller = "Home", action = "Index", id = UrlParameter.Optional, area = "ForumAdmin" },
				namespaces.Distinct().ToArray()
			);
		}
	}
}